﻿// Write a program that reverses the words in given sentence.
// Example: 
// "C# is not C++, not PHP and not Delphi!" -> "Delphi not and PHP, not C++ not is C#!".
using System;
using System.Text;

public class ReverseSentenceWords
{
    public static void Main()
    {
        string sentence = "C# is not C++, not PHP and not Delphi!";

        Console.WriteLine(ReverseWords(sentence));
    }

    public static string ReverseWords(string sentence)
    {
        string[] words = sentence.Split(new char[] { ' ', ',', '.', '!', '?' }, StringSplitOptions.RemoveEmptyEntries);
        string[] punctuation = sentence.Split(words, StringSplitOptions.RemoveEmptyEntries);
        Array.Reverse(words);

        StringBuilder reversedWords = new StringBuilder(sentence.Length);
        for (int i = 0; i < words.Length; i++)
        {
            reversedWords.Append(words[i]);
            reversedWords.Append(punctuation[i]);
        }

        return reversedWords.ToString();
    }
}